package com.spukmk3me.video;

import com.spukmk3me.debug.Logger;
import com.spukmk3me.resource.Resource;
import com.spukmk3me.scene.Entity;

public class Polygon extends Entity
{
    public Polygon()
    {
        this( false, null );
    }
    
    public Polygon( boolean isStatic, float[] coords )
    {
        super( (Resource)null );
        this.isStatic = isStatic;
        
        if ( isStatic )
        {
            m_coords = new float[ coords.length ];
            System.arraycopy( coords, 0, m_coords, 0, coords.length );
        }
        else
            setCoords( coords );
    }

    @Override
    public byte getType()
    {
        return ET_POLYGON;
    }

    @Override
    public Entity duplicate()
    {
        return new Polygon( isStatic, m_coords );
    }
    
    public void setCoords( float[] coords )
    {
        if ( !isStatic )
            m_coords = coords;
        /* $if SPUKMK3ME_DEBUG$ */
        else
            Logger.trace( "Warning: setup coordinates for static polygon. No effect." );
        /* $endif$ */
    }
    
    public float[] getCoords()
    {
        return m_coords;
    }
    
    public void setFlags( int flags )
    {
        m_renderFlags = flags;
    }
    
    public int getFlags()
    {
        return m_renderFlags;
    }
    
    @Override
    public int getWidth()
    {
        return 0;
    }
    
    @Override
    public int getHeight()
    {
        return 0;
    }
    
    @Override
    public boolean isTimeless()
    {
        return true;
    }
    
    public static Polygon createRectangle( float width, float height, boolean isStatic )
    {
        float[] coords = {
            0f, 0f,
            width, 0f,
            width, height,
            0f, height
        };
        
        return new Polygon( isStatic, coords );
    }
    
    public static final int FLAGS_LINE = 0x00000001;
    
    public final boolean isStatic;
    
    private float[] m_coords;
    private int     m_renderFlags;
}
